package com.zhangsun.springActiveMq.consumer;

import com.zhangsun.springActiveMq.bean.User;
import com.zhangsun.springActiveMq.common.ActiveMqConstant;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.jms.ObjectMessage;

@Component
public class QueueConsumer {

    @JmsListener(destination = ActiveMqConstant.QUEUE_HELLO_1, containerFactory = ActiveMqConstant.QUEUE_LISTENER)
    public void consumer(String msg) {
        System.out.println(ActiveMqConstant.QUEUE_HELLO_1 + "：" + msg);
    }

    @JmsListener(destination = ActiveMqConstant.QUEUE_HELLO_2, containerFactory = ActiveMqConstant.QUEUE_LISTENER)
    public void consumer2(ObjectMessage text) {
        try {
            User user = (User) text.getObject();
            System.out.println(ActiveMqConstant.QUEUE_HELLO_2 + "：" + user.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
